//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <iostream>

#include "WekaLoadAttributeSelectionBuffer.h"
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
using namespace std;
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
int main (int argc, char** argv) {
  
  String* namefileBuffer = NULL;
  String* namefileOut    = NULL;
  
  if (argc < 3) {
    
    cout << "Error in the input parameters! Must by like: " << endl;
    cout << "./LoadAttributesFromWekaFile <Filename with attributes selection buffer>";
    cout <<                             " <Filename with a list of attributes>";
    cout << endl;
    
    return 0;
    
  }
  else {
    
    namefileBuffer = new String(argv[1]);
    namefileOut    = new String(argv[2]);
    
    cout << "----------------------------------------------------------------------------------------------------------------" << endl;
    cout << " Filename with attributes selection buffer : " << argv[1] << endl;
    cout << "        Filename with a list of attributes : " << argv[2] << endl;    
    cout << "----------------------------------------------------------------------------------------------------------------" << endl;
    
  }
  
  WekaLoadAttributeSelectionBuffer* wekaLoadAttributeSelectionBuffer       = new WekaLoadAttributeSelectionBuffer ();
  WekaLoadAttributeSelectionBuffer* wekaLoadAttributeSelectionBufferStored = new WekaLoadAttributeSelectionBuffer ();
  
  cout << "Preparing the files..." << endl;
  wekaLoadAttributeSelectionBuffer->NamefileBuffer(namefileBuffer);
  
  cout << "Loading the data..." << endl;
  if (!wekaLoadAttributeSelectionBuffer->LoadData())
    cout << "Error loading data!" << endl;
  if (!wekaLoadAttributeSelectionBufferStored->LoadListFromFile(namefileOut))
    cout << "Error loading data!" << endl;
  
  cout << "Reading and merging the attributes..." << endl;
  if (!wekaLoadAttributeSelectionBuffer->MergeList(wekaLoadAttributeSelectionBufferStored->ListAttributes()))
    cout << "Error merging the attributes!" << endl;
  
  cout << "Writing the result in the output file..." << endl;
  if (!wekaLoadAttributeSelectionBuffer->WriteSummary(namefileOut))
    cout << "Error writing the new list of attributes!" << endl;
  
  cout << "Finished..." << endl << "Good Bye" << endl;
  
  if (wekaLoadAttributeSelectionBuffer)       delete wekaLoadAttributeSelectionBuffer;
  if (wekaLoadAttributeSelectionBufferStored) delete wekaLoadAttributeSelectionBufferStored;
  
  if (namefileBuffer)                         delete namefileBuffer;
  if (namefileOut)                            delete namefileOut;

  return EXIT_SUCCESS;
  
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//

